package com.zpc.transformfile;

import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author : zpc20 //作者
 * @version : 1.0 // 版本
 * @ClassName : Client  //类名
 * @Description : 客户端接收文件  //描述
 * @Date: 2024-11-24  下午 10:57
 */
public class Client {
    public static void main(String[] args) {
        try(Socket socket = new Socket("127.0.0.1", 8081)) {
            FileInputStream fileInputStream = new FileInputStream("net/temp.txt");
            System.out.println("上传文件中....");
            OutputStream outputStream = socket.getOutputStream();
            byte[] buffer = new byte[1024];
            int len;
            while ((len = fileInputStream.read(buffer)) != -1) {
                 outputStream.write(buffer,0,len); // 从字节数组中写入从0到len
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
